package com.fy56.platform.goodsTracking.police.unit;

import com.alibaba.fastjson.JSON;
import com.fy56.platform.goodsTracking.model.GoodstrackedRecordPublic;
import com.fy56.platform.goodsTracking.model.GoodstrackedRecordTopPublic;
import com.fy56.platform.goodsTracking.model.SysCompany;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by XTK on 2017-02-28.
 */
@Service
public class BuildJson {

    public String buildConsignmentBillMaster(GoodstrackedRecordTopPublic top, Map<String, String> map) {
        String code;
        if (top.getDatatype().equals("1"))
            code = "05";
        else if (top.getDatatype().equals("2"))
            code = "03";
        else code = "02";

        String json = "'MessageFunctionCode':'" + code + "','" +
                "Body':{" +
                "'ShippingNoteNumber':'" + top.getConsignmentbillnumber() + "'," +
                "'OriginalDocumentNumber':'" + top.getManualnumber() + "'," +
                "'GoodsSelfNumber':'" + top.getGoodsnumber() + "'," +
                "'InHouseIdentifier':'F6'," +
                "'ConsignmentDateTime':'" + top.getConsignmentbilldate() + "'," +
                "'Remark':''" +
                "}," +
                "'ConsignorInfo':{" +
                "'ConsignorCompanySenderCode':'" + map.get(top.getSendcompany()) + "'," +
                "'ConsignorCode':'" + top.getConsignorcompanycode() + "'," +
                "'ConsignorName':'" + top.getConsignor() + "'," +
                "'ConsignorIDCard':'" + top.getConsignoridcard() + "'," +
                "'ConsignorTelephoneNumber':'" + top.getConsignormobiletelephone() + "'," +
                "'ConsignorCountrySubdivisionName':'哈尔滨'," +
                "'ConsignorCountrySubdivisionCode':'2301'," +
                "'PlaceOfLoading':'" + top.getPlaceofloading() + "'," +
                "'ResquestedLoadingDateTime':'" + top.getConsignmentbilldate() + "'" +
                "}," +
                "'ConsigneeInfo':{" +
                "'ConsigneeCompanySenderCode':'" + map.get(top.getReceivecompany()) + "'," +
                "'ConsigneeCode':'" + top.getConsigneecompanycode() + "'," +
                "'ConsigneeName':'" + top.getConsignee() + "'," +
                "'ConsigneeIDCard':'" + top.getConsigneeidcard() + "'," +
                "'ConsigneeTelephoneNumber':'" + top.getConsigneemobiletelephone() + "'," +
                "'ConsigneeCountrySubdivisionName':'哈尔滨'," +
                "'ConsigneeCountrySubdivisionCode':'2301'," +
                "'GoodsReceiptPlace':'" + top.getReceivecompany() + "'" +
                "}," +
                "'GoodsInfo':[{" +
                "'DescriptionOfGoods':'" + top.getGoodsname() + "'," +
                "'GoodsType':'10'," +
                "'TotalNumberOfPackages':'" + top.getTotalnumberofpackages() + "'," +
                "'PackageType':'00'}]" +
                "";
        return json;
    }

    public String buildGoodstrackedRecord(GoodstrackedRecordPublic sub) {
        String code;
        if (sub.getDatatype().equals("1"))
            code = "05";
        else if (sub.getDatatype().equals("2"))
            code = "03";
        else code = "02";
        String statusCode = "";
       /* 6	已完成预约	托运单确认、待处理 5,7
        24	已发车	已发车 31
        1	完全到达	已到货 1
        72	已确认收货	已签收 72 */
        if (sub.getTypenum().equals("5") || sub.getTypenum().equals("7")) {
            statusCode = "6";
        }

        String json =
                "'MessageFunctionCode':'" + code + "'," +
                        "'ShippingNoteNumber':'" + sub.getConsignmentbillnumber() + "'," +
                        "'OriginalDocumentNumber':'" + sub.getManualnumber() + "'," +
                        "'GoodsSelfNumber':'" + sub.getGoodsnumber() + "'," +
                        "'InHouseIdentifier':'F6'," +
                        "'TransportStatusCode':'" + statusCode + "'," +
                        "'StatusChangeDateTime':'" + sub.getSystime() + "'," +
                        "'PlaceOrLocationIdentification':'" + sub.getCreatecompanyname() + "'," +
                        "'NameOfPerson':'" + sub.getCreateoperator() + "'," +
                        "'Remark':'" + sub.getTypename() + "'";
        return json;
    }

    public String buildCompany(SysCompany company, String Code) {
        return "'MessageFunctionCode':'" + Code + "'," +
                "'BR_Code':'" + company.getCompanycode() + "'," +
                "'BR_Name':'" + company.getCompanyname() + "'," +
                "'BR_Add':'+" + company.getCompanyaddress() + "'," +
                "'BR_Tel':'" + company.getBossheadphone() + "'," +
                "'BR_DistCode':'2301'," +
                "'BR_Linkman':'" + company.getBosshead() + "'," +
                "'BR_LinkmanNO':'" + company.getBossheadphone() + "'," +
                "'BR_LONGITUDE':''," +
                "'BR_LATITUDE':''," +
                "'REMARK':''";
    }


    public String buildGoods() {
        return
                "'MessageFunctionCode':'02'," +
                        "'CONTENTS_TYPE_CODE':'10'," +
                        "'CONTENTS_TYPE_NAME':'散货'";
    }

    public String buildProduct() {
        return
                "'MessageFunctionCode':'02'," +
                        "'PRODUCT_ID':'20'," +
                        "'PRODUCT_NAME':'干线运输'";
    }

}
